/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aptech.edu.ixj.impl;

import aptech.edu.ixj.dto.AnswerDto;
import aptech.edu.ixj.dto.QuestionDto;
import aptech.edu.ixj.entity.Answer;
import aptech.edu.ixj.entity.Question;
import aptech.edu.ixj.interfaces.IQADao;
import aptech.edu.ixj.interfaces.IQALogic;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Node;

/**
 *
 * @author ChauNTM
 */
public class QALogicImpl implements IQALogic {

    IQADao qaDao = new QADaoImpl();

    public List<AnswerDto> getlisAnswers(String quesId) {
        List<AnswerDto> answerDto = new ArrayList<AnswerDto>();
        AnswerDto answer;
        for (Answer a : qaDao.getListAnswer(quesId)) {
            answer = new AnswerDto();
            answer.setIdAnswer(a.getIdAnswer());
            answer.setOption(a.getOption());
            answer.setChecked(true);
            answer.setQuestionId(a.getQuestionId());
            answer.setRate("");
            answer.setRating(a.getRating());
            answerDto.add(answer);
        }

        return answerDto;
    }

    public List<QuestionDto> getListQuestion(String surveyId) {
        List<QuestionDto> questionDto = new ArrayList<QuestionDto>();
        QuestionDto question;
        for (Question q : qaDao.getListQuestion(surveyId)) {
            question = new QuestionDto();
            question.setAnswer(getlisAnswers(q.getIdQuestion()));
            question.setCald(q.getCald());
            question.setContent(q.getContent());
            question.setIdQuestion(q.getIdQuestion());
            question.setNumber("");
            questionDto.add(question);
        }
        return questionDto;
    }

    public boolean save() {
        return (qaDao.save());
    }

    public boolean removeAnser(String answerId) {
        return (qaDao.removeAnswer(answerId));
    }

    public boolean removeQuestion(String quesId) {
        return (qaDao.removeQuestion(quesId));
    }

    public void reemove(Node nodeParen, Node nodeRemove) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public boolean createQuestion(QuestionDto question) {
        Question qs = new Question();
        qs.setContent(question.getContent());
        qs.setIdQuestion(question.getIdQuestion());
        return qaDao.createQuestion(qs);
    }

    public boolean createAnswer(AnswerDto answer) {
        Answer ans = new Answer();
        ans.setIdAnswer(answer.getIdAnswer());
        ans.setOption(answer.getOption());
        ans.setQuestionId(answer.getQuestionId());
        ans.setRating(answer.getRating());
        return qaDao.createAnswer(ans);
    }
}
